package org.wang.generalcode.modules.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wang.generalcode.modules.sys.pojo.entity.DictItem;
import org.wang.generalcode.modules.sys.service.IDictItemService;
import org.wang.generalcode.modules.sys.pojo.vo.DictItemVO;
import org.wang.generalcode.support.mybaties.Condition;
import org.wang.generalcode.support.mybaties.Query;
import org.wang.generalcode.support.result.Result;
import org.wang.generalcode.support.utils.Func;

import javax.validation.Valid;

/**
 * 字典数据表 控制器
 *
 * @author wz
 * @since 2024-08-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dictItem")
@Schema(description = "字典数据表", name = "字典数据表接口")
public class DictItemController {

	private final IDictItemService dictItemService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Schema(description = "详情", example = "传入dictItem")
	public Result<DictItem> detail(DictItem dictItem) {
		DictItem detail = dictItemService.getOne(Condition.getQueryWrapper(dictItem));
		return Result.success(detail);
	}

	/**
	 * 分页 字典数据表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@Schema(description = "分页", example = "传入dictItem")
	public Result<IPage<DictItem>> list(DictItem dictItem, Query query) {
		IPage<DictItem> pages = dictItemService.page(Condition.getPage(query), Condition.getQueryWrapper(dictItem));
		return Result.success(pages);
	}

	/**
	 * 自定义分页 字典数据表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Schema(description = "分页", example = "传入dictItem")
	public Result<IPage<DictItemVO>> page(DictItemVO dictItem, Query query) {
		IPage<DictItemVO> pages = dictItemService.selectDictItemPage(Condition.getPage(query), dictItem);
		return Result.success(pages);
	}

	/**
	 * 新增 字典数据表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Schema(description = "新增", example = "传入dictItem")
	public Result save(@Valid @RequestBody DictItem dictItem) {
		return Result.judge(dictItemService.save(dictItem));
	}

	/**
	 * 修改 字典数据表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@Schema(description = "修改", example = "传入dictItem")
	public Result update(@Valid @RequestBody DictItem dictItem) {
		return Result.judge(dictItemService.updateById(dictItem));
	}

	/**
	 * 新增或修改 字典数据表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Schema(description = "新增或修改", example = "传入dictItem")
	public Result submit(@Valid @RequestBody DictItem dictItem) {
		return Result.judge(dictItemService.saveOrUpdate(dictItem));
	}


	/**
	 * 删除 字典数据表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@Schema(description = "删除", example = "传入ids")
	public Result remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
		return Result.judge(dictItemService.removeByIds(Func.toLongList(ids)));
	}


}
